<template>
  <div class="avatar_box">
    <el-breadcrumb separator="/" >
      <el-breadcrumb-item :to="{ path: '/test' }" active-text-color="#ffd04b">首页</el-breadcrumb-item>

      <el-breadcrumb-item>停车场管理</el-breadcrumb-item>
      <el-breadcrumb-item>车辆列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--    主体部分-->
    <el-card  class="mainn">


      <!-- 用户列表 -->
      <el-table :data="buslist"  style="hight: 200px"
                border stripe>
        <el-table-column type="index" ></el-table-column>

        <el-table-column label="姓名" prop="username"></el-table-column>
        <el-table-column label="车牌号" prop="carnumber"></el-table-column>
        <el-table-column label="状态" prop="state"></el-table-column>



      </el-table>

    </el-card>

  </div>
</template>
<script>
  export default {
    created (){
      this.getBusList();
    },
    data(){
      return{

        queryInfo:{
          query:"",//查询信息
          pageNum: 1,//当前页
          pageSize: 5,//每页最大数
        },
        menuList: [],
        buslist:[],

        addDialogVisible: false,
        // 添加用户表单项
        addForm: {
          name:'',
          state:'',

        },


        // 控制修改用户对话框显示/隐藏
        editDialogVisible:false,
        // 修改用户信息
        editForm:{},
        // 验证规则


      }

    },
    methods:{

      async addCar(){
        this.$refs.addFormRef.validate(async valid=>{
          if( !valid ) return;
          // 发起请求
          const {data:res} = await this.$http.post("addCar",this.addForm);
          if (res != "success") {
            userinfo.state = !userinfo.state;
            return this.$message.error("操作失败！！！");
          }
          this.$message.success("操作成功！！！");
          //隐藏
          this.addDialogVisible = false;
          this.getCarList();
        })
      },
      async addDialogClosed(){
        this.$refs.addFormRef.resetFileds();


      }
      ,async deleteUser(name){
        // 弹框
        console.log(name);
        const confirmResult = await this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).catch(err => err)
        // 成功删除为confirm 取消为 cancel
        if(confirmResult!='confirm'){
          return this.$message.info("已取消删除");
        }
        const {data:res} = await this.$http.delete("deleteUser?name="+name);
        if (res != "success") {
          return this.$message.error("操作失败！！！");
        }
        this.$message.success("操作成功！！！");
        this.getUserList();
      },
      async getFindCarList() {
        // 调用post请求
        const { data: res } = await this.$http.get("txtfindcar", {
          params: this.queryInfo
        });
        this.carlist = res.data; // 将返回数据赋值
        // this.total = res.numbers; // 总个数
        // console.log(queryInfo);



      },
      async getBusList() {
        // 调用post请求
        const { data: res } = await this.$http.get("txtfindbus", {
          params: this.queryInfo
        });
        this.buslist = res.data; // 将返回数据赋值
        // this.total = res.numbers; // 总个数
        // console.log(queryInfo);



      },
      async deleteCar(name){
        // 弹框
        console.log(name);
        const confirmResult = await this.$confirm('此操作将永久删除该停车位, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).catch(err => err)
        // 成功删除为confirm 取消为 cancel
        if(confirmResult!='confirm'){
          return this.$message.info("已取消删除");
        }
        const {data:res} = await this.$http.delete("deleteCar?name="+name);
        if (res != "success") {
          return this.$message.error("操作失败！！！");
        }
        this.$message.success("操作成功！！！");
        this.getCarList();
      },
      async getCarList() {
        // 调用post请求
        const { data: res } = await this.$http.get("carlist", {

        });
        this.carlist = res.data; // 将返回数据赋值
        // this.total = res.numbers; // 总个数
        // console.log(queryInfo);



      },

    }
  }


</script>

<style scoped>

</style>
